<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org"
>
<!--        税务报表        -->

<head>

    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/custom.form.css">

</head>
<style>
    .cx>div{
        margin-bottom: 10px;
    }
</style>
<body>

<div class="dept-table">
    <!--  ---------------------------------搜索条件  -->
    <div id="searchParam" >
        <div class="layui-form-item cx">
            <div class="layui-input-inline">
                <input type="text" id="enterprise_name" class="layui-input" autocomplete="off" placeholder="请输入企业名称">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="social_credit_code" class="layui-input" autocomplete="off" placeholder="请输入统一社会信用代码">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="legal_representative" class="layui-input" autocomplete="off" placeholder="请输入法定代表人">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="business_place" class="layui-input" autocomplete="off" placeholder="请输入经营场所">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="business_scope" class="layui-input" autocomplete="off" placeholder="请输入经营范围">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="contacts" class="layui-input" autocomplete="off" placeholder="请输入联系人">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="contact_information" class="layui-input" autocomplete="off" placeholder="请输入联系方式">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="enterprise_status" class="layui-input" autocomplete="off" placeholder="请输入企业状态">
            </div>
            <div class="layui-input-inline layui-form">
                <select id="report_status">
                    <option value="0">请选择税务状态</option>
                    <option value="1">正常</option>
                    <option value="2">税务异常</option>
                    <option value="3">黑名单</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <input type="text" readonly class="layui-input" id="create_time" placeholder="请选择创建日期">
            </div>
            <div class="layui-input-inline ">
                <button class="layui-btn" onclick="search()" id="search">查询</button>
            </div>
        </div>
    </div>

    <!--  -------------------------上传弹出框  -->
    <div class="upload-report" hidden>
        <div style="height: 40px;background-color: #009688">
            <span style="line-height: 40px;color: white;letter-spacing: 5px;margin-left: 5px">税务状态</span>
            <a class="layui-btn" href="javascript:;" onclick="uploadClose()" style="width: 40px;float: right">
                <i style="margin-right: -8px;" class="layui-icon layui-icon-close"></i>
            </a>
        </div>
        <div class="layui-input-inline layui-form" style="margin-top: 20px;margin-left: 25%;">
            <select id="report_status_excel">
                <option value="1">正常</option>
                <option value="2">税务异常</option>
                <option value="3">黑名单</option>
            </select>
        </div>
        <div style="margin-left: 25%;margin-top: 20px;">
            <button style="width: 212px;height: 40px;letter-spacing: 5px;" class="layui-btn layui-btn-sm" id="uploadAnnualExcel">选择文件</button>
        </div>
    </div>

    <!--  ------------------------------表格  -->
    <table class="layui-table" id="annualsTable" lay-filter="annualsTable"></table>
</div>
<div id="deptTree" style="display: none"></div>

<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="qingdiao" >清吊
        </button>
        <button class="layui-btn layui-btn-sm" lay-event="uploadAnnual" id="uploadAnnual" style="float: right;margin-right: -118px;" >上传
        </button>
    </div>
</script>

<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script>
    //获取token
    var token = CoreUtil.getData("access_token");
    //地址栏转义token中的#号
    var tokenQuery = token.replace("#", "%23");
    var tableIns2;
    var uploadIns;
    var table = layui.table;
    var upload = layui.upload;
    var form = layui.form;
    var layer = layui.layer;
    var $ = jQuery = layui.jquery;
    var laydate = layui.laydate;
    var tree = layui.tree;
    var transfer = layui.transfer;
    var createStartTime = null;
    var createEndTime = null;
    layui.use(['table', 'layer', 'laydate', 'tree', 'transfer','upload'], function () {
        tableIns2 = table.render({
            elem: '#annualsTable'// 表格id
            , contentType: 'application/json'
            , headers: {"authorization": token}
            , page: true //开启分页
            , limits: [10,100,1000,10000]
            , limit: 10 //每页默认显示的数量
            , url: '/taxationRpt/findAllTaxationReport' //数据接口
            , method: 'POST'
            , toolbar: '#toolbar'
            ,defaultToolbar: []
            , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                console.log(res);
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data.list) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data.list) ? null : res.data.list //解析数据列表
                }
            },
            cols: [
                [
                    {field: 'enterpriseName', title: '企业名称'},
                    {field: 'socialCreditCode', title: '统一社会信用代码', width: 200},
                    {field: 'legalRepresentative', title: '法定代表人', width: 100},
                    {field: 'businessPlace', title: '经营场所', width: 300},
                    {field: 'businessScope', title: '经营范围', width: 200},
                    {field: 'contacts', title: '联系人', width: 80},
                    {field: 'contactInformation', title: '联系方式', width: 125},
                    {field: 'status', title: '状态', width: 60},
                    {
                        field: 'reportStatus', title: '税务状态', width: 90, templet: function (item) {
                            if (item.reportStatus === 1 || item.reportStatus === "1") {
                                return '正常';
                            }
                            if (item.reportStatus === 2 || item.reportStatus === "2") {
                                return '税务异常';
                            }
                            if (item.reportStatus === 3 || item.reportStatus === "3") {
                                return '黑名单';
                            }
                        }
                    },
                    {
                        field: 'createTime', title: '创建日期',width: 140, templet: function (item) {
                            return "<div>"+layui.util.toDateString(item.createTime, 'yyyy年MM月dd日')+"</div>";
                        }
                    }
                ]
            ]
        });

        //上传事件
        uploadIns = upload.render({
            elem: '#uploadAnnualExcel'
            , before: function (obj) {
                this.data = {'reportStatus' : $("#report_status_excel").val()}
            }
            , headers: {"authorization": token}
            , url: '/taxationRpt/taxationReportUploadExcel'
            // , data: {'reportStatus' : $("#report_status_excel").val()}
            , size: '3072'
            , accept: 'file' //普通文件
            , exts: 'xlsx|xls' //允许上传的文件后缀
            , method: 'post'
            , done: function(res){ //返回值接收
                console.log(res);
                $(".upload-report").hide();
                if(res.data == 1){
                    layer.msg('导入成功！', {
                    }, function(){
                        location.reload();
                    });
                }else{
                    layer.msg('导入失败！', {
                    }, function(){
                        location.reload();
                    });
                }
            }
        });

        //操作项事件
        table.on('toolbar(annualsTable)', function (obj) {
            switch (obj.event) {
                case 'qingdiao':
                    qingdiaoAnnual();
                    break;
                case 'uploadAnnual':
                    uploadAnnual();
                    break;
            }
        });

        /**
         * 点击清吊事件
         */
        var qingdiaoAnnual = function () {
            CoreUtil.sendGet("/qingdiaoRpt/triggerQingDiaoForTaxationReport",{},function (res) {
                console.log(res);
                if(res.data == 1){
                    layer.msg('清吊成功！', {
                    }, function(){
                        location.reload();
                    });
                }else{
                    layer.msg('清吊失败！', {
                    }, function(){
                        location.reload();
                    });
                }
            })
        };

        /**
         * 点击上传按钮弹出选择框
         * 选择框选择是否是上报状态
         */
        var uploadAnnual = function (){
            $(".upload-report").show();
        };

    });

    /**
     * 设置日期
     */
    laydate.render({
        elem: '#create_time'
        , type: 'date'
        , range: '~'
        , done: function (value, date, endDate) {
            if (value != null && value != undefined && value != "") {
                createStartTime = value.split("~")[0];
                createEndTime = value.split("~")[1];
            } else {
                createStartTime = null;
                createEndTime = null;
            }

        }
    });

    /**
     * 隐藏上传弹出框
     */
    function uploadClose() {
        $(".upload-report").hide();
    }

    /**
     * 条件查询按钮方法
     */
    function search() {
        //这里以搜索为例
        tableIns2.reload({
            where: { //设定异步数据接口的额外参数，任意设
                enterpriseName: $("#enterprise_name").val(),
                socialCreditCode: $("#social_credit_code").val(),
                legal_representative: $("#legal_representative").val(),
                business_place: $("#business_place").val(),
                business_scope: $("#business_scope").val(),
                contacts: $("#contacts").val(),
                contact_information: $("#contact_information").val(),
                status: $("#status").val(),
                reportStatus: $("#report_status").val(),
                createStartTime : createStartTime,
                createEndTime: createEndTime
            }
            , page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    }
</script>
</body>
</html>